package org.dormi.learn.product.port.config;

import org.dormi.learn.event.EventStore;
import org.dormi.learn.product.application.material.MaterialCreateCmd;
import org.dormi.learn.product.application.material.MaterialQuery;
import org.dormi.learn.product.domain.material.ModuleDependency;
import org.dormi.learn.product.domain.material.repo.MaterialRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * add description here
 *
 * @author : dormi330
 * @version : 1.0
 */
@Configuration
public class MaterialModuleConfig {

    @Autowired private MaterialRepository materialRepository;

    @Autowired private EventStore eventStore;

    @Bean
    public MaterialCreateCmd materialCreateCmd() {
        return new MaterialCreateCmd(eventStore);
    }

    @Bean
    public MaterialQuery materialQuery() {
        return new MaterialQuery();
    }

    @PostConstruct
    private void inject() {
        ModuleDependency md = ModuleDependency.instance();
        if (md == null) {
            new ModuleDependency(materialRepository);
        }
    }

}
